package com.xuecheng.learning.listener;

import com.xuecheng.base.constants.RabbitMqConstants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Service;

/**
 * 接收消息通知处理类
 *
 * @author itcast
 */
@Slf4j
@Service
public class PayNotifyListener {

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = RabbitMqConstants.Queue.LEARNING_PAY_SUCCESS),
            exchange = @Exchange(name = RabbitMqConstants.Exchange.ORDERS, type = ExchangeTypes.FANOUT)
    ))
    public void receive(String message) {
        log.info("接收到支付结果通知，选课记录id：{}", message);

        //TODO  根据消息内容，更新选课记录、向我的课程表插入记录
//        boolean b = myCourseTablesService.saveChooseCourseSuccess(message);
//        if (!b) {
//            XueChengPlusException.cast("保存选课记录失败");
//        }
    }
}

